home *** CD-ROM | disk | FTP | other *** search
/ Gamers Delight 2 / Gamers Delight 2.iso / Aminet / game / role / pinfocom_3_0.lha / Source / variable.c < prev   
C/C++ Source or Header  |  1992-10-22  |  3KB  |  171 lines

  1. /* variable.c
  2.  *
  3.  *  ``pinfocom'' -- a portable Infocom Inc. data file interpreter.
  4.  *  Copyright (C) 1987-1992  InfoTaskForce
  5.  *
  6.  *  This program is free software; you can redistribute it and/or modify
  7.  *  it under the terms of the GNU General Public License as published by
  8.  *  the Free Software Foundation; either version 2 of the License, or
  9.  *  (at your option) any later version.
  10.  *
  11.  *  This program is distributed in the hope that it will be useful,
  12.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  *  GNU General Public License for more details.
  15.  *
  16.  *  You should have received a copy of the GNU General Public License
  17.  *  along with this program; see the file COPYING.  If not, write to the
  18.  *  Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  */
  20.  
  21. /*
  22.  * $Header: RCS/variable.c,v 3.0 1992/10/21 16:56:19 pds Stab $
  23.  */
  24.  
  25. #include    "infocom.h"
  26.  
  27. void
  28. get_var A1(word, var)
  29. {
  30.     store(load_var(var));
  31. }
  32.  
  33. word
  34. load_var A1(word, var)
  35. {
  36.     extern byte     *global_ptr;
  37.     extern word     *stack_var_ptr;
  38.     extern word     *stack;
  39.  
  40.     byte            *ptr;
  41.  
  42.     if (var == 0)
  43.         return (*stack);
  44.     else
  45.     {
  46.         if (var < LOCAL_VARS)
  47.         {
  48.             return (*(stack_var_ptr - (var - 1)));
  49.         }
  50.         else
  51.         {
  52.             ptr = global_ptr + ((var - LOCAL_VARS) << 1);
  53.             return (Z_TO_WORD(ptr));
  54.         }
  55.     }
  56. }
  57.  
  58. void
  59. put_var A2(word, var, word, value)
  60. {
  61.     extern byte     *global_ptr;
  62.     extern word     *stack_var_ptr;
  63.     extern word     *stack;
  64.  
  65.     word            *svp;
  66.     byte            *ptr;
  67.  
  68.     if (var == 0)
  69.         *stack = value;
  70.     else
  71.     {
  72.         if (var < LOCAL_VARS)
  73.         {
  74.             svp = stack_var_ptr - (var - 1);
  75.             *svp = value;
  76.         }
  77.         else
  78.         {
  79.             ptr = global_ptr + ((var - LOCAL_VARS) << 1);
  80.             *ptr++ = value >> 8;
  81.             *ptr = value;
  82.         }
  83.     }
  84. }
  85.  
  86. void
  87. push A1(word, value)
  88. {
  89.     extern word     *stack;
  90.  
  91.     *(--stack) = value;
  92. }
  93.  
  94. void
  95. pop A1(word, var)
  96. {
  97.     extern word     *stack;
  98.  
  99.     put_var(var, *stack++);
  100. }
  101.  
  102. void
  103. inc_var A1(word, var)
  104. {
  105.     put_var(var, load_var(var) + 1);
  106. }
  107.  
  108. void
  109. dec_var A1(word, var)
  110. {
  111.     put_var(var, load_var(var) - 1);
  112. }
  113.  
  114. void
  115. inc_chk A2(word, var, word, threshold)
  116. {
  117.     word    value;
  118.  
  119.     value = load_var(var) + 1;
  120.     put_var(var, value);
  121.     if ((signed_word)value > (signed_word)threshold)
  122.         ret_value(1);
  123.     else
  124.         ret_value(0);
  125. }
  126.  
  127. void
  128. dec_chk A2(word, var, word, threshold)
  129. {
  130.     word    value;
  131.  
  132.     value = load_var(var) - 1;
  133.     put_var(var, value);
  134.     if ((signed_word)value < (signed_word)threshold)
  135.         ret_value(1);
  136.     else
  137.         ret_value(0);
  138. }
  139.  
  140. word
  141. load A1(int, mode)
  142. {
  143.     extern word     *stack;
  144.  
  145.     word            var;
  146.  
  147.     /*
  148.      * Mode 0 = Immediate Word;
  149.      * Mode 1 = Immediate Byte;
  150.      * Mode 2 = Variable;
  151.      */
  152.  
  153.     --mode;
  154.     if (mode < 0)
  155.         return (next_word());
  156.     if (mode == 0)
  157.     {
  158.         byte b;
  159.  
  160.         NEXT_BYTE(b);
  161.         return ((word)b);
  162.     }
  163.  
  164.     NEXT_BYTE(var);
  165.  
  166.     if (var == 0)
  167.         return (*stack++);
  168.     else
  169.         return (load_var(var));
  170. }
  171.